﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BTKERP.Model;
using BTKERP.BLL.Inventory;
using BTKERP.BLL.UserMgmt;

namespace BTKERP.MVCWeb.Controllers
{
    public class RestrictController : ControllerBase
    {
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            if (SessionEntity == null)
            {
                Response.Redirect("/Default.aspx");
                return;
            }
        }

        public List<SelectListItem> GetCategoryList()
        {
            List<Category> categories = InventoryInfoMgt.GetCategories();
            return (from Category car in categories
                     select new SelectListItem()
                     {
                         Text = car.Name,
                         Value = car.Id.ToString()
                     }).ToList();

        }

        public List<SelectListItem> GetUnitTypeList()
        {
            List<UnitType> types = InventoryInfoMgt.GetUnitTypes();
            return (from UnitType type in types
                    select new SelectListItem()
                    {
                        Text=  type.Name,
                        Value = type.Id.ToString()
                    }).ToList();
        }


        public List<SelectListItem> GetUserList(string id= "")
        {
            List<User> users = UserBLL.GetALlUsers();
            return (from user in users
                    select new SelectListItem()
                    {
                        Text = user.DisplayName, 
                        Value = user.UserName,
                        Selected = user.UserID.ToString() == id 
                    }).ToList();
        }


        public SelectList GetUnitTypeSelectList()
        {
            List<UnitType> types = InventoryInfoMgt.GetUnitTypes();
            return new SelectList(from t in types select t, "Id", "Name");
        }

        public SelectList GetCategorySelectList()
        {
            List<Category> categries = InventoryInfoMgt.GetCategories();
            return new SelectList(from c in categries select c, "Id", "Name");
        }

        public SelectList GetUnitSelectList()
        {
            List<Unit> units = InventoryInfoMgt.GetUnits();
            return new SelectList(from u in units select u, "Id", "Name");
        }

        public SelectList GetCoutrySelectList()
        {
            List<Country> countries = InventoryInfoMgt.GetCoutires();
            return new SelectList(from c in countries select c, "Id", "Name");
        }

        public SelectList GetCitySelectList()
        {
            List<City> cities = InventoryInfoMgt.GetCities();
            return new SelectList(from c in cities select c, "Id", "Name");
        }

        public SelectList GetWarehouseSelectList()
        {
            List<Warehouse> warehouses = InventoryInfoMgt.GetWarehouses();
            return new SelectList(from w in warehouses select w, "Id", "Name");
        }

        public SelectList GetSupplierSelectList()
        {
            List<Supplier> suppliers = InventoryInfoMgt.GetSuppliers();
            return new SelectList(from s in suppliers select s, "Id", "Name");
        }
    }
}
